﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EQual.MainModule.Projects.Tasks.Models
{

/// <summary>
///Delete THIS
/// </summary>
   public  class TasksPresentationModel : EQual.Infrastructure.MVPFramework.Models.PresentationModelBase<DataAccesLayer.Task>
    {

        public TasksPresentationModel()
        {
            this.DataFactory = new DataAccesLayer.EQualDataLayerFactory();
            this.View = new EQual.MainModule.Projects.Tasks.Views.TasksGridView();
            this.View.Model = this;
        }
        protected override IEnumerable<DataAccesLayer.Task > GetCollection()
        {
            if (ActiveProject != null)
                return this.DataFactory.GetProjectsAccesLayer().GetTasks(ActiveProject) as IEnumerable<DataAccesLayer.Task>;
            else return new WpfApplicationExperimental.DAOCollection<DataAccesLayer.Task>(); 
        }

        protected override void CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            base.CollectionChanged(sender, e);
        }

        #region IProjectsPresentationModel Members

        public new System.Collections.IEnumerable ItemsCollection
        {

            get { return base.ItemsCollection; }
        }

        public string HeaderInfo
        {
            get;
            set;
        }


        public EQual.MainModule.Projects.Tasks.Views.TasksGridView View
        {
            get;
            set;

        }

        DataAccesLayer.Task  _task;
        public object ActiveItem
        {
            get { return _task; }

            set
            {
                _task = value as DataAccesLayer.Task;
                InvokePropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("ActiveItem"));
            }
        }


        DataAccesLayer.Project  __project;
        public object ActiveProject
        {
            get { return __project; }
            set{
                   __project  = value as DataAccesLayer.Project ;
                   InvokePropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("ActiveProject"));
            }

        }

        #endregion

        internal void AddNewTask(System.Collections.IList iList)
        {
            this.DataFactory.GetProjectsAccesLayer().AddNewTaskToProject(ActiveProject, iList);
        }

        internal void AddNewTask(object p)
        {
            this.DataFactory.GetProjectsAccesLayer().AddNewTaskToProject(ActiveProject, p);
        }
    }
}
